home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / misc / Dictionary.lha / Dictionary.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2000-09-30  |  3.5 KB  |  141 lines

  1. /*
  2. **
  3. ** $VER: Dictionary.rexx 1.7 (30.09.2000)
  4. ** 
  5. ** (C)2000 Damir Arh, All Rights Reserved.
  6. **
  7. ** E-mail: damir.arh@telesat.si
  8. ** WWW:    http://damir.gajba.net
  9. **
  10. ** FUNCTION:
  11. **    Acts as an interface to a dictionary file in specified format
  12. **
  13. ** USAGE:
  14. **    Dictionary DICTFILE
  15. **
  16. ** PARAMETERS:
  17. **    DICTFILE - dictionary filename
  18. **
  19. ** $Id: Dictionary.rexx,v 1.7 2000/09/30 14:51:11 damir Sta $
  20. **
  21. ** $Log: Dictionary.rexx,v $
  22. ** Revision 1.7  2000/09/30 14:51:11  damir
  23. ** - major rewrite (increased speed and memory requirements, reduced file access)
  24. **
  25. ** Revision 1.6  2000/09/30 14:22:32  damir
  26. ** - rewritten the keyword manipulation to reduce file access
  27. **
  28. ** Revision 1.5  2000/09/16 20:51:21  damir
  29. ** - fixed a bug which caused the script to quit in case of non-alphabetical root search
  30. **
  31. ** Revision 1.4  2000/09/02 15:48:34  damir
  32. ** - fixed a bug introduced in previous revision
  33. **
  34. ** Revision 1.3  2000/09/01 11:12:53  damir
  35. ** - fixed a bug which caused the script to exit in certain cases
  36. **
  37. ** Revision 1.2  2000/09/01 10:17:27  damir
  38. ** - program speed up by indexing the starting letter positions
  39. **
  40. ** Revision 1.1  2000/08/31 19:45:10  damir
  41. ** Initial revision
  42. **
  43. */
  44.  
  45. parse arg DictionaryFile
  46. options results
  47.  
  48. if ~open(infile,DictionaryFile,'R') then do
  49.     cecho("Error","Can't open the dictionary file.")
  50.     exit
  51. end
  52.  
  53. say "Initializing, please wait..."
  54.  
  55. /* get the keywords */
  56.  
  57. NextLine = "empty"
  58. keywords.TITLE = "Untitled"
  59. do while NextLine ~= ""
  60.     NextLine = readln(infile)
  61.     FirstWord = word(NextLine,1)
  62.     if left(FirstWord,1) = "#" then do
  63.         key = upper(substr(FirstWord,2))
  64.         keywords.key = subword(NextLine,2)
  65.     end
  66. end
  67. t = 0
  68. Beginning.1 = t
  69.  
  70. /* find the starting positions for all the letters */
  71.  
  72. do i = 2 to 27
  73.     do while (upper(left(NextLine,1)) < d2c(c2d('A')-1+i)) & (~eof(infile)) 
  74.         NextLine = readln(infile)
  75.         parse var NextLine LPart ' - ' RPart
  76.         entry.t = LPart
  77.         description.t = RPart
  78.         t = t + 1
  79.     end
  80.     Beginning.i = t
  81. end
  82.  
  83. close(infile)
  84.  
  85. help()
  86.  
  87. /* main loop */
  88.  
  89. Query = ""
  90. do while Query ~="!"
  91.     writech(stdin,"> ")
  92.     parse pull Query
  93.     if Query = "?" then help()
  94.     else if Query = "!" then exit
  95.     else if word(Query,1) = "#" then say keyword(word(Query,2))
  96.     else if word(Query,1) = "*" then findroot(subword(Query,2))
  97.     else say find(Query)
  98. end
  99.  
  100.  
  101. /* functions */
  102.  
  103. help: /* print out the help text */
  104. say ""
  105. say "Dictionary.rexx 1.5 (c)2000 Damir Arh, All rights reserved"
  106. say ""
  107. say "Current dictionary file: " || keywords.TITLE
  108. say ""
  109. say "Commands:"
  110. say "?           - displays this help text"
  111. say "!           - quits program"
  112. say "# keyword   - returns the contents of the 'keyword'"
  113. say "* something - returns all dictionary entries that start with 'something'"
  114. say "something   - returns the dictionary entry for 'something'"
  115. say ""
  116. return 0
  117.  
  118. keyword: /* display keyword contents */
  119. key = upper(arg(1))
  120. if keywords.key = keywords || '.' || key then return "unknown keyword"
  121. else return keywords.key
  122.  
  123. find: /* display dictionary entry */
  124. l = c2d(upper(left(arg(1),1)))-c2d('A')+1
  125. if l<1 | l>26 then l=1
  126. u = l + 1
  127. do i = Beginning.l to Beginning.u - 2
  128.     if upper(entry.i) = upper(arg(1)) then return description.i
  129. end
  130. return "word not in dictionary"
  131.  
  132. findroot: /* display all entries with the given root */
  133. l = c2d(upper(left(arg(1),1)))-c2d('A')+1
  134. if l<1 | l>26 then l=1
  135. u = l + 1
  136. do i = Beginning.l to Beginning.27 - 2
  137.     if upper(left(entry.i,length(arg(1)))) = upper(arg(1)) then say entry.i '-' description.i
  138.     if upper(left(entry.i,length(arg(1)))) > upper(arg(1)) then return 0
  139. end
  140. return 0
  141.